/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package parser.extraData.tradeTabs;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

/**
 * @author Mr. Poke
 *
 */
public class TradeTabsLoader
{
	private static SortedMap<Integer, TradeTab> tabsMap = new TreeMap<Integer, TradeTab>();
	
	public static Map<Integer, TradeTab> getTabsMap()
	{
		return tabsMap;
	}
	
	public static Map<Integer, TradeTab> load()
	{
		try
		{
			JAXBContext jc = JAXBContext.newInstance("parser.extraData.tradeTabs");
			Unmarshaller unmarshaller = jc.createUnmarshaller();

			Tradetabs collection;
			collection = (Tradetabs) unmarshaller.unmarshal(new File("extraData/tradeTabs/tradeTabs.xml"));
			System.out.println("Size of TradeTab: " + collection.getTradetab().size());
			Map<Integer, TradeTab> map = new HashMap<Integer, TradeTab>();
			for (TradeTab tab : collection.getTradetab())
				map.put(tab.getNpcId(), tab);
			return map;
		}
		catch (JAXBException e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
